# -*- coding=utf-8 -*-

import urllib.parse
import urllib.request
from bs4 import BeautifulSoup

import requests

# req = urllib.request.Request(scrapeUrl)
# req.add_header('User-Agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)')
# response = urllib.request.urlopen(req)
# html = response.read()
#
# bsObj = BeautifulSoup(html, "html.parser")

def get_content(count,url):
    print("开始第" + str(count) + "次请求:"+url)
    headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
               'Accept-Encoding': 'gzip, deflate, br',
               'Accept-Language': 'zh-CN,zh;q=0.9',
               'Cache-Control': 'max-age=0',
               'Connection': 'keep-alive',
               'Host': 'db.yaozh.com',
               'Cookie': '_ga=GA1.2.512734659.1515666397; PHPSESSID=3lhqascg9sfmhimrmek0iep4n6; Hm_lvt_65968db3ac154c3089d7f9a4cbb98c94=1515666398,1515666452,1516175475; _gid=GA1.2.1338173813.1516265800; yaozh_userId=529246; UtzD_f52b_saltkey=hTQI2WqJ; UtzD_f52b_lastvisit=1516262414; _ga=GA1.3.512734659.1515666397; yaozh_uidhas=1; yaozh_mylogin=1516266064; UtzD_f52b_ulastactivity=1516266010%7C0; UtzD_f52b_lastact=1516266065%09uc.php%09; think_language=zh-CN; WAF_SESSION_ID=3568c162bd11e2cac029c8ce64014bfe; _gat=1; Hm_lpvt_65968db3ac154c3089d7f9a4cbb98c94=1516331882',
               'Upgrade-Insecure-Requests': '1',
               'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36'}
    requests.packages.urllib3.disable_warnings()
    html_body_opener = requests.get(url, verify=False, headers=headers).content
    html_body_source = html_body_opener.decode("unicode-escape")
    print("第"+str(count)+"次请求成功:"+url)
    return html_body_source

if __name__=='__main__':
    page_base_url = 'https://db.yaozh.com/hmap/'
    for page_num in range(1,20):
        #print(page_num)
        hospital_url = page_base_url + str(page_num) + '.html'
        get_content(page_num,hospital_url)